using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Collections;

namespace Acms.SqlDal
{
    public class UserPostUploadFileDal : Base
    {
        public enum Fields
        {
            UserPostUploadId,
            Key,
            FileId,
            FileType,
            Name,
            Width,
            Height
        }

        protected override void ReadRecord(System.Collections.Hashtable table, System.Data.SqlClient.SqlDataReader reader)
        {
            GetReaderValue<int>(Fields.UserPostUploadId, reader, table);
            GetReaderValue<string>(Fields.Key, reader, table);
            GetReaderValue<int>(Fields.FileId, reader, table);
            GetReaderValue<int>(Fields.FileType, reader, table);
            GetReaderValue<string>(Fields.Name, reader, table);
            GetReaderValue<int>(Fields.Width, reader, table);
            GetReaderValue<int>(Fields.Height, reader, table);
        }

        public void Delete(int userPostUploadId, string key)
        {
            SqlCommand cmd = CreateCommand("Delete");
            AddInputParameter(cmd, "UserPostUploadId", userPostUploadId, SqlDbType.Int);
            AddInputParameter(cmd, "Key", key, SqlDbType.VarChar, 20);
            ExecuteCommand(cmd);
        }

        public void Update(int userPostUploadId, string key, int fileId, ref int fileTypeId, ref string name, ref int width, ref int height)
        {
            SqlCommand cmd = CreateCommand("Put");
            AddInputParameter(cmd, "UserPostUploadId", userPostUploadId, SqlDbType.Int);
            AddInputParameter(cmd, "Key", key, SqlDbType.VarChar, 20);
            AddInputParameter(cmd, "FileId", fileId, SqlDbType.Int);
            AddOutputParameter(cmd, "FileTypeOut", SqlDbType.Int);
            AddOutputParameter(cmd, "NameOut", SqlDbType.VarChar, 50);
            AddOutputParameter(cmd, "WidthOut", SqlDbType.Int);
            AddOutputParameter(cmd, "HeightOut", SqlDbType.Int);

            ExecuteCommand(cmd);

            fileTypeId = GetOutputValue<int>(cmd, "FileTypeOut");
            name = GetOutputValue<string>(cmd, "NameOut");
            width = GetOutputValue<int>(cmd, "WidthOut");
            height = GetOutputValue<int>(cmd, "HeightOut");

        }

        public Hashtable[] GetAllByUserPostUploadId(int userPostUploadId)
        {
            SqlCommand cmd = CreateCommand("GetAllByUserPostUploadId");
            AddInputParameter(cmd, "UserPostUploadId", userPostUploadId, SqlDbType.Int);
            return ExecuteGetCollection(cmd);
        }
    }

}
